var express = require('express');
var router = express.Router();;
var bshoplists=require("../model/bshoplists");
var bshoparticles=require("../model/bshoparticles");
var xgoodslist=require("../model/xgoodslist");
var xlooklist=require("../model/xlooklist");
var xacticallist=require("../model/xacticallist");
var xdetailslist=require("../model/xdetailslist");
const {classifyOperation,shoesOperation,shopcerOperation}=require("../model/classifyOper");


router.get('/list', function(req, res) {
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  bshoplists.findall(function (data) {
    res.json(data)
  })
});
router.get('/article', function(req, res) {
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  bshoparticles.findall(function (data) {
    res.json(data)
  })
});
router.post('/listson', function(req, res) {
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  let z = req.body.z;
  let y = req.body.y;
  let j = req.body.j;
  bshoplists.find({"pinpai":z,"price":{$gt:y,$lt:j}},function (data) {
    res.json(data)
  })
});
router.get('/app',(req,res)=>{
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  xgoodslist.findGoods(function (data){
    res.json(data);
  })
});
  router.get('/api',(req,res)=>{
    res.header("Access-Control-Allow-Origin","*");
    res.header("Access-Control-Allow-Headers","X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    xlooklist.findList(function (data){
      res.json(data);
    })
  });
router.get('/test',(req,res)=>{
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  xacticallist.findImg(function (data){
    res.json(data);
  })
});
  router.get('/detail',(req,res)=>{
    res.header("Access-Control-Allow-Origin","*");
    res.header("Access-Control-Allow-Headers","X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    xdetailslist.finddetail(function (data){
      res.json(data);
    })
  });
router.get("/shopclassify",function(req,res){
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  let classifydata = new classifyOperation();
  classifydata.findAll({},(err,result)=>{
    res.json(result);
  })
});
router.get("/shoes",function(req,res){
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  let shoesdata = new shoesOperation();
  shoesdata.findshoes({},(err,result)=>{
    res.json(result);
  })
});
router.post("/shopcar",function(req,res){
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  let shopcardata = new shopcerOperation();
  var goodsObj={
    name:req.body.name,
    goodsid:req.body.goodsid,
    storename:req.body.storename,
    img1:req.body.img1,
    newprice:req.body.newprice,
    icon:req.body.icon,
    color:req.body.color,
    colorimg:req.body.colorimg,
    num:req.body.num,
  };
  shopcardata.addshopcardata(goodsObj,(err,result)=>{
    console.log(result);
  });
});
router.get("/shopcars",function(req,res){
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","X-Requested-With");
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  let shopcardata2 = new shopcerOperation();
  shopcardata2.getshopcardata({},(err,result)=>{
    res.json(result);
  });
});

module.exports = router;
